package com.jd.platform.gobrs.worker.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;


/**
 * @program: gobrs
 * @ClassName ThreadPoolConfig
 * @description:
 * @author: sizegang
 * @create: 2022-01-13 23:32
 * @Version 1.0
 **/
@Configuration
@EnableAsync
public class ThreadPoolConfig {
    @Bean(name = "executeHitSumThreadPool")
    public ThreadPoolTaskExecutor executeHitSumThreadPool() {
        ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
        pool.setKeepAliveSeconds(300);
        //核心线程池数
        pool.setCorePoolSize(5);
        //最大线程
        pool.setMaxPoolSize(30);
        //队列容量
        pool.setQueueCapacity(10000);
        //队列满，线程被拒绝执行策略
        // 丢弃老任务
        pool.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
        pool.setThreadNamePrefix("live-service-");
        return pool;
    }
}
